class Solution844 {
    public static void main(String[] args) {
        System.out.println(backspaceCompare("ab#c", "ad#c"));
    }
    public static boolean backspaceCompare(String s, String t) {
           char[] arr1 = s.toCharArray() ;
           char[] arr2 = t.toCharArray() ;
            StringBuilder strbu1 = new StringBuilder() ;
            StringBuilder strbu2 = new StringBuilder() ;
            for(char ch : arr1){
                if(ch == '#'){
                   if(strbu1.length() >= 1){
                    strbu1.deleteCharAt(strbu1.length()-1) ; 
                   }
                }else{
                    strbu1.append(ch) ; 
                }
            }
              for(char ch : arr2){
                if(ch == '#'){
                   if(strbu2.length() >= 1){
                    strbu2.deleteCharAt(strbu2.length()-1) ; 
                   }
                }else{
                    strbu2.append(ch) ; 
                }
            }

        return strbu1.toString().equals(strbu2.toString()) ;
    }
}